whichfun[expr_]:=Which[Head[expr]===Plus,2 expr, Head[expr]===Times,expr*expr,Head[expr]===List,Reverse[expr]]

{whichfun[{a,b}],whichfun[a+b],whichfun[a*b],whichfun[a^b]}

whichfun1[expr_]:=Which[Head[expr]===Plus,2 expr, Head[expr]===Times,expr*expr,Head[expr]===List,Reverse[expr],True, expr]

{whichfun1[{a,b}],whichfun1[a+b],whichfun1[a*b],whichfun1[a^b]}

switchfun[expr_]:=Switch[Head[expr],Plus,2 expr, Times,expr*expr,List,Reverse[expr]]

{switchfun[{a,b}],switchfun[a+b],switchfun[a*b],switchfun[a^b]}

switchfun1[expr_]:=Switch[Head[expr],Plus,2 expr, Times,expr*expr,List,Reverse[expr],_,expr]

{switchfun1[{a,b}],switchfun1[a+b],switchfun1[a*b],switchfun1[a^b]}

DW[y_, x_] :=
	Which[y===x, 1,
		           Length[y]===2&& 
		          y[[0]]===Power&&
			        y[[1]]===x,
		                                 n=y[[2]];n x^(n-1),
		           y===Cos[x], -Sin[x],
	           	y===Sin[x], Cos[x],
		           True, "Unknown"]

{DW[(x^3), x], DW[y, y], DW[Sin[z], z], DW[w^(1/2), w], DW[f[r], r]}

DS[y_, x_] :=
	Switch[y,  x,               1,
		                      x^n_,        y[[2]]x^(y[[2]]-1),
		                     Cos[x],    -Sin[x],
		                     _, "Unknown"]

{DS[(x^3), x], DS[y, y], DS[Cos[z], z],DS[w^(1/2), w], DS[f[r], r]}